home *** CD-ROM | disk | FTP | other *** search
/ Champak 145 / (Vol 145) Dec 21 2011.iso / Games / hanna-in-a-choppa.swf / scripts / __Packages / com / mosesSupposes / fuse / FuseKitCommon.as next >
Encoding:
Text File  |  2011-12-21  |  17.0 KB  |  428 lines

  1. class com.mosesSupposes.fuse.FuseKitCommon
  2. {
  3.    static var logOutput;
  4.    static var VERSION = "Fuse Kit 2.1.3r1 Copyright (c) 2006 Moses Gunesch, MosesSupposes.com under MIT Open Source License";
  5.    static var VERBOSE = true;
  6.    static var ALL = "ALL";
  7.    static var ALLCOLOR = "ALLCOLOR";
  8.    static var cbTicker = 0;
  9.    function FuseKitCommon()
  10.    {
  11.    }
  12.    static function _cts()
  13.    {
  14.       return "|_tint|_tintPercent|_brightness|_brightOffset|_contrast|_invertColor|_colorReset|_colorTransform|";
  15.    }
  16.    static function _resetTo100()
  17.    {
  18.       return "|_alpha|_contrast|_invertColor|_tintPercent|_xscale|_yscale|_scale|";
  19.    }
  20.    static function _resetTo0()
  21.    {
  22.       return "|_brightness|_brightOffset|_colorReset|_rotation|";
  23.    }
  24.    static function _underscoreable()
  25.    {
  26.       return com.mosesSupposes.fuse.FuseKitCommon._cts() + "_frame|_x|_y|_xscale|_yscale|_scale|_width|_height|_size|_rotation|_alpha|_fade|_visible|";
  27.    }
  28.    static function _cbprops()
  29.    {
  30.       return "|skipLevel|cycles|roundResults|extra1|extra2|func|scope|args|startfunc|startscope|startargs|updfunc|updscope|updargs|";
  31.    }
  32.    static function _fuseEvents()
  33.    {
  34.       return "|onStart|onStop|onPause|onResume|onAdvance|onComplete|";
  35.    }
  36.    static function _fuseprops()
  37.    {
  38.       return "|command|label|delay|event|eventparams|target|addTarget|trigger|startAt|ease|easing|seconds|duration|time|";
  39.    }
  40.    static function _validateFuseCommand(c, inGroup, hasArg, outputLevel, simple)
  41.    {
  42.       var _loc1_ = false;
  43.       var _loc2_ = false;
  44.       switch(c)
  45.       {
  46.          case "start":
  47.          case "stop":
  48.          case "pause":
  49.          case "resume":
  50.          case "setStartProps":
  51.             if(inGroup != true)
  52.             {
  53.                _loc1_ = true;
  54.             }
  55.             break;
  56.          case "delay":
  57.          case "trigger":
  58.             if(simple == true)
  59.             {
  60.                if(hasArg == true)
  61.                {
  62.                   _loc1_ = true;
  63.                }
  64.             }
  65.             else
  66.             {
  67.                _loc2_ = true;
  68.             }
  69.             inGroup = false;
  70.             break;
  71.          case "skipTo":
  72.             if(hasArg == true && inGroup != true)
  73.             {
  74.                _loc1_ = true;
  75.                break;
  76.             }
  77.       }
  78.       if(outputLevel > 0 && _loc1_ == false)
  79.       {
  80.          com.mosesSupposes.fuse.FuseKitCommon.error("109",c,inGroup,_loc2_);
  81.       }
  82.       return _loc1_;
  83.    }
  84.    static function output(s)
  85.    {
  86.       if(typeof com.mosesSupposes.fuse.FuseKitCommon.logOutput == "function")
  87.       {
  88.          com.mosesSupposes.fuse.FuseKitCommon.logOutput(s);
  89.       }
  90.       else
  91.       {
  92.          trace(s);
  93.       }
  94.    }
  95.    static function error(errorCode)
  96.    {
  97.       var _loc3_ = arguments[1];
  98.       var _loc4_ = arguments[2];
  99.       var _loc6_ = arguments[3];
  100.       if(com.mosesSupposes.fuse.FuseKitCommon.VERBOSE != true)
  101.       {
  102.          com.mosesSupposes.fuse.FuseKitCommon.output("[FuseKitCommon#" + errorCode + "]");
  103.          return undefined;
  104.       }
  105.       var _loc2_ = "";
  106.       var _loc5_ = "\n";
  107.       switch(errorCode)
  108.       {
  109.          case "001":
  110.             _loc2_ += "** ERROR: When using simpleSetup to extend prototypes, you must pass the Shortcuts class. **";
  111.             _loc2_ += _loc5_ + " import com.mosesSupposes.fuse.*;";
  112.             _loc2_ += _loc5_ + " ZigoEngine.simpleSetup(Shortcuts);" + _loc5_;
  113.             break;
  114.          case "002":
  115.             _loc2_ += "** ZigoEngine.doShortcut: shortcuts missing. Use the setup commands: import com.mosesSupposes.fuse.*; ZigoEngine.register(Shortcuts); **";
  116.             break;
  117.          case "003":
  118.             _loc2_ += _loc5_ + "*** Error: DO NOT use #include \"lmc_tween.as\" with this version of ZigoEngine! ***" + _loc5_;
  119.             break;
  120.          case "004":
  121.             _loc2_ += "** ZigoEngine.doTween - too few arguments [" + _loc3_ + "].";
  122.             if(Boolean(_loc4_) == true)
  123.             {
  124.                _loc2_ += " If you are trying to use Object Syntax without Fuse, pass FuseItem in your register() or simpleSetup() call. **";
  125.             }
  126.             else
  127.             {
  128.                _loc2_ += " Object syntax call failed. **";
  129.             }
  130.             break;
  131.          case "005":
  132.             _loc2_ += "** ZigoEngine.doTween - missing targets[" + _loc3_ + "] and/or props[" + _loc4_ + "] **";
  133.             break;
  134.          case "006":
  135.             _loc2_ += "** Error: easing shortcut string not recognized (\"" + _loc3_ + "\"). You may need to pass the in PennerEasing class during register or simpleSetup. **";
  136.             break;
  137.          case "007":
  138.             _loc2_ += "- ZigoEngine: Target locked [" + _loc3_ + "], ignoring tween call [" + _loc4_ + "]";
  139.             break;
  140.          case "008":
  141.             _loc2_ += "** You must register the Shortcuts class in order to use easy string-type callback parsing. **";
  142.             break;
  143.          case "009":
  144.             _loc2_ += "** ZigoEngine: A callback parameter \"" + _loc3_ + "\" was not recognized. **";
  145.             break;
  146.          case "010":
  147.             _loc2_ += "** " + (_loc3_ != true ? "FuseItem" : "ZigoEngine") + " unable to parse " + (_loc4_ != 1 ? String(_loc4_) + " callbacks[" : "callback[") + _loc6_ + "]. Try using the syntax {scope:this, func:\"myFunction\"} **";
  148.             break;
  149.          case "011":
  150.             _loc2_ += "- ZigoEngine: Callbacks discarded via skipLevel 2 option [" + _loc3_ + "|" + _loc4_ + "].";
  151.             break;
  152.          case "012":
  153.             _loc2_ += "- Engine set props or ignored no-change tween on: " + _loc3_ + ", props passed:[" + _loc4_ + "], endvals passed:[" + _loc6_ + "]";
  154.             break;
  155.          case "013":
  156.             _loc2_ += "- Engine added tween on:\n\ttargets:[" + _loc3_ + "]\n\tprops:[" + _loc4_ + "]\n\tendvals:[" + _loc6_ + "]";
  157.             break;
  158.          case "014":
  159.             _loc2_ += "** Error: easing function passed is not usable with this engine. Functions need to follow the Robert Penner model. **";
  160.             break;
  161.          case "015":
  162.             _loc2_ += "** Error: The CustomEasing class must be passed during setup (register or simpleSetup) to use custom easing Arrays. **";
  163.             break;
  164.          case "016":
  165.             _loc2_ += "[ ZigoEngine.TIME_MULTIPLIER: " + String(Number(Number(_loc3_) * 100)) + "% ]";
  166.             break;
  167.          case "101":
  168.             _loc2_ += "** ERROR: Fuse simpleSetup was removed in version 2.0! **";
  169.             _loc2_ += _loc5_ + " You must now use the following commands:";
  170.             _loc2_ += _loc5_ + _loc5_ + "\timport com.mosesSupposes.fuse.*;";
  171.             _loc2_ += _loc5_ + "\tZigoEngine.simpleSetup(Shortcuts, PennerEasing, Fuse);";
  172.             _loc2_ += _loc5_ + "Note that PennerEasing is optional, and FuseFMP is also accepted. (FuseFMP.simpleSetup is run automatically if included.)" + _loc5_;
  173.             break;
  174.          case "102":
  175.             _loc2_ += "** Fuse " + _loc3_ + " index or label not found (" + _loc4_ + ") or out of range. **";
  176.             break;
  177.          case "103":
  178.             _loc2_ += "** Fuse skipTo (" + _loc3_ + ")  ignored - targets the current index (" + _loc4_ + "). **";
  179.             break;
  180.          case "104":
  181.             _loc2_ += "** Fuse fastForward index out of play range (" + _loc3_ + ") - skipTo has been called instead. **";
  182.             break;
  183.          case "105":
  184.             _loc2_ += "** An unsupported Array method was called on Fuse. **";
  185.             break;
  186.          case "106":
  187.             _loc2_ += "** ERROR: You have not set up Fuse correctly. **";
  188.             _loc2_ += _loc5_ + "You must now use the following commands (PennerEasing is optional).";
  189.             _loc2_ += _loc5_ + "\timport com.mosesSupposes.fuse.*;";
  190.             _loc2_ += _loc5_ + "\tZigoEngine.simpleSetup(Shortcuts, PennerEasing, Fuse);" + _loc5_;
  191.             break;
  192.          case "107":
  193.             _loc2_ += "** Fuse :: id not found - Aborting open(). **";
  194.             break;
  195.          case "108":
  196.             _loc2_ += "** Fuse.startRecent: No recent Fuse found to start! **";
  197.             break;
  198.          case "109":
  199.             _loc2_ += "** Command \"" + _loc3_ + "\" discarded. ";
  200.             if(_loc4_ == true)
  201.             {
  202.                _loc2_ += "Not allowed within a group. **";
  203.             }
  204.             else if(_loc6_ == true)
  205.             {
  206.                _loc2_ += "Not supported in Object Syntax, use the " + _loc3_ + " property instead. **";
  207.             }
  208.             else
  209.             {
  210.                _loc2_ += "The command may be unrecognized or missing an argument. **";
  211.             }
  212.             break;
  213.          case "110":
  214.             _loc2_ += "** " + _loc3_ + " illegal Fuse property discarded:\"" + _loc4_ + "\". Bezier keywords other than x and y cannot be set as start values. **";
  215.             break;
  216.          case "112":
  217.             _loc2_ += "** Fuse: missing com.mosesSupposes.fuse.ZigoEngine! Cannot tween. **";
  218.             break;
  219.          case "113":
  220.             _loc2_ += "** FuseItem: A callback has been discarded. Actions with a command may only contain: label, delay, scope, args. **";
  221.             break;
  222.          case "115":
  223.             _loc2_ += _loc3_ + " overlapping prop discarded: " + _loc4_;
  224.             break;
  225.          case "116":
  226.             _loc2_ += "** FuseItem Error: Delays within groups (arrays) and start/update callbacks are not supported when using Fuse without ZigoEngine. Although you need to restructure your Fuse, it should be possible to achieve the same results. **" + _loc5_;
  227.             break;
  228.          case "117":
  229.             _loc2_ += "** " + _loc3_ + ": infinite cycles are not allowed within Fuses - discarded. **";
  230.             break;
  231.          case "118":
  232.             _loc2_ += "** " + _loc3_ + ": No targets found!" + (_loc4_ != true ? "  [Skipping tween parameters in this action] **" : "  [Unable to set start props] **");
  233.             break;
  234.          case "119":
  235.             _loc2_ += "** " + _loc3_ + ": " + (_loc4_ != 1 ? _loc4_ + " actions in the group" : "") + " missing targets" + (_loc6_ != true ? " **" : " during setStartProps **");
  236.             break;
  237.          case "120":
  238.             _loc2_ += "** " + _loc3_ + ": conflict with \"" + _loc4_ + "\". Property might be doubled within a grouped-action array. **";
  239.             break;
  240.          case "121":
  241.             _loc2_ += "** Fuse timecode formatting requires \"00:\" formatting (example:\"01:01:33\" yields 61.33 seconds.) **";
  242.             break;
  243.          case "122":
  244.             _loc2_ += "** Event \"" + _loc3_ + "\" reserved by Fuse. **";
  245.             break;
  246.          case "123":
  247.             _loc2_ += "** A Fuse event parameter failed in " + _loc3_ + " **";
  248.             break;
  249.          case "124":
  250.             _loc2_ += "** " + _loc3_ + ": trigger:" + _loc4_ + " ignored - only one trigger is allowed per action **";
  251.             break;
  252.          case "125":
  253.             _loc2_ += _loc3_ + " Warning - fastForward hit an item during its tween cycle, may malfunction.";
  254.             break;
  255.          case "201":
  256.             _loc2_ += "**** FuseFMP cannot initialize argument " + _loc3_ + " (BitmapFilters cannot be applied to this object type) ****";
  257.             break;
  258.          case "202":
  259.             _loc2_ += "** FuseFMP error: A " + _loc3_ + " could not be created for " + _loc4_ + " **";
  260.             break;
  261.          case "203":
  262.             _loc2_ += "** FuseFMP.setFilterProps - too few arguments passed (" + _loc3_ + ") - minimum 2 required. **";
  263.             break;
  264.          case "204":
  265.             _loc2_ += "** FuseFMP.setFilterProps could not locate the filter passed. (" + _loc3_ + ") **";
  266.       }
  267.       com.mosesSupposes.fuse.FuseKitCommon.output(_loc2_);
  268.    }
  269.    static function parseCallback(callback, targets, outputLevel, callerIsEngine, addprefix)
  270.    {
  271.       if(callback._vcb == true)
  272.       {
  273.          return callback;
  274.       }
  275.       var validCBs = {_vcb:true,skipLevel:_global.com.mosesSupposes.fuse.ZigoEngine.SKIP_LEVEL,cycles:1};
  276.       if(callback == undefined)
  277.       {
  278.          return validCBs;
  279.       }
  280.       var cbErrors = [];
  281.       if(typeof callback == "object")
  282.       {
  283.          if(callback.skipLevel != undefined && typeof callback.skipLevel == "number" && callback.skipLevel != _global.com.mosesSupposes.fuse.ZigoEngine.SKIP_LEVEL)
  284.          {
  285.             if(callback.skipLevel >= 0 && callback.skipLevel <= 2)
  286.             {
  287.                validCBs.skipLevel = callback.skipLevel;
  288.             }
  289.          }
  290.          if(callback.cycles != undefined)
  291.          {
  292.             if(typeof callback.cycles == "number" && callback.cycles > -1)
  293.             {
  294.                validCBs.cycles = callback.cycles;
  295.             }
  296.             else if(callback.cycles.toUpperCase() == "LOOP")
  297.             {
  298.                validCBs.cycles = 0;
  299.             }
  300.          }
  301.          if(callback.extra1 != undefined)
  302.          {
  303.             validCBs.extra1 = callback.extra1;
  304.          }
  305.          if(callback.extra2 != undefined)
  306.          {
  307.             validCBs.extra2 = callback.extra2;
  308.          }
  309.          if(callback.roundResults === true || callback.roundResults === false)
  310.          {
  311.             validCBs.roundResults = callback.roundResults;
  312.          }
  313.       }
  314.       else
  315.       {
  316.          callback = {func:callback};
  317.       }
  318.       var prefixes = ["start","upd",""];
  319.       var easyfuncparse = _global.com.mosesSupposes.fuse.Shortcuts.parseStringTypeCallback;
  320.       for(var i in prefixes)
  321.       {
  322.          var prefix = prefixes[i];
  323.          var fstr = callback[prefix + "func"];
  324.          if(fstr != undefined && typeof fstr == "string" && fstr.indexOf("(") > -1)
  325.          {
  326.             if(easyfuncparse != undefined)
  327.             {
  328.                var efc = easyfuncparse(fstr);
  329.                if(efc.func != undefined)
  330.                {
  331.                   callback[prefix + "scope"] = efc.scope;
  332.                   callback[prefix + "func"] = efc.func;
  333.                   callback[prefix + "args"] = efc.args;
  334.                }
  335.             }
  336.             else if(outputLevel > 0)
  337.             {
  338.                com.mosesSupposes.fuse.FuseKitCommon.error("008");
  339.             }
  340.          }
  341.       }
  342.       var basescope = callback.scope;
  343.       for(var i in callback)
  344.       {
  345.          var fi = i.toLowerCase().indexOf("func");
  346.          if(fi > -1)
  347.          {
  348.             var prefix = i.slice(0,fi);
  349.             var func = callback[i];
  350.             var args = callback[prefix + "args"];
  351.             var scope = callback[prefix + "scope"] != undefined ? callback[prefix + "scope"] : basescope;
  352.             if(typeof func == "string" && scope[func] == undefined)
  353.             {
  354.                for(var j in targets)
  355.                {
  356.                   var targ = targets[j];
  357.                   if(typeof targ[func] == "function")
  358.                   {
  359.                      scope = targ;
  360.                      break;
  361.                   }
  362.                   if(typeof targ._parent[func] == "function")
  363.                   {
  364.                      scope = targ._parent;
  365.                      break;
  366.                   }
  367.                }
  368.                if(scope == undefined && _level0[func] != undefined)
  369.                {
  370.                   scope = _level0;
  371.                }
  372.                if(scope == undefined && _global[func] != undefined)
  373.                {
  374.                   scope = _global;
  375.                }
  376.             }
  377.             if(typeof func != "function")
  378.             {
  379.                if(typeof scope[String(func)] == "function")
  380.                {
  381.                   func = scope[String(func)];
  382.                }
  383.                else
  384.                {
  385.                   func = eval(String(func));
  386.                }
  387.             }
  388.             if(func == undefined)
  389.             {
  390.                cbErrors.push(String((addprefix != null ? addprefix + i : i) + ":" + (typeof callback[i] != "string" ? callback[i] : "\"" + callback[i] + "\"") + "/" + prefix + "scope:" + scope));
  391.             }
  392.             else
  393.             {
  394.                if(args != undefined && !(args instanceof Array))
  395.                {
  396.                   args = [args];
  397.                }
  398.                if(prefix == "")
  399.                {
  400.                   prefix = "end";
  401.                }
  402.                validCBs[prefix] = {s:scope,f:func,a:args};
  403.                if(callerIsEngine == true)
  404.                {
  405.                   validCBs[prefix].id = ++com.mosesSupposes.fuse.FuseKitCommon.cbTicker;
  406.                }
  407.                if(prefix == "start")
  408.                {
  409.                   validCBs.start.fired = false;
  410.                }
  411.             }
  412.          }
  413.          else if(com.mosesSupposes.fuse.FuseKitCommon._cbprops().indexOf("|" + i + "|") == -1)
  414.          {
  415.             com.mosesSupposes.fuse.FuseKitCommon.error("009",i);
  416.          }
  417.       }
  418.       if(cbErrors.length > 0 && outputLevel > 0)
  419.       {
  420.          if(outputLevel > 0)
  421.          {
  422.             com.mosesSupposes.fuse.FuseKitCommon.error("010",callerIsEngine,cbErrors.length,cbErrors.toString());
  423.          }
  424.       }
  425.       return validCBs;
  426.    }
  427. }
  428.